const moduleA = {
  // namespaced: true,用于添加命名空间
  // 让getters、mutations、actions的调用也state一样也放在模块名称下
  namespaced: true,
  state: {
    name: "zhangsan",
    age: 20,
    height: 180,
    likes: ["c", "t", "r", "l"],
  },
  getters: {
    // getters有两个参数，分别是state和getters
    // getters需要传参的时候，要写成柯里化(curry)函数
    doubleAge: (state) => (n) => state.age * n,
    reverseName(state, getters) {
      return state.name.split("").reverse().join("") + getters.doubleAge(3);
    },
  },
  mutations: {
    changeName(state) {
      state.name = "lisi";
    },
    changeAge(state, payload) {
      state.age += payload.n;
      // }, 1000);
    },
    changeHeight(state, payload) {
      state.height *= payload.n;
    },
  },
  actions: {
    asyncChangeHeight({ commit }, payload) {
      setTimeout(() => {
        // console.log(context);
        commit("changeHeight", payload);
      }, 1000);
    },
  },
};

export default moduleA;
